package com.zoke.password.model;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.zoke.password.Conf;
import com.zoke.password.tools.PersistTool;

/**
 * Created by wulijie on 2018/6/2.
 */
public class User {
    public String address;//当做uid使用
    public String password;//手势锁密码
    public String lastActive;//最后登录时间
    public String created;//创建时间
    public String preference;//是否开启了手势锁

    public static void save(User user) {
        if (user == null) return;
        mUser = user;
        String json = new Gson().toJson(user);
        PersistTool.saveString(Conf.KEY_USER, json);
    }

    /**
     * 清空
     */
    public static void clear() {
        PersistTool.saveString(Conf.KEY_USER, "");
    }

    public static User mUser;

    public static User getUser() {
        if (mUser == null) {
            String json = PersistTool.getString(Conf.KEY_USER, "");
            if (!TextUtils.isEmpty(json)) {
                mUser = new Gson().fromJson(json, User.class);
            }
        }
        return mUser;
    }

    /**
     * 判断是否经登录了
     *
     * @return
     */
    public static boolean isLogin() {
        return getUser() != null;
    }

}
